<template>
  <div class="admin-container">
    <div class="container">
      <div class="admin">
        <div class="menu">
                <el-table
                  :data="tableData"
                  style="width: 100%">
                  <el-table-column
                    prop="id"
                    label="编号"
                    type='index'>
                  </el-table-column>
                  <el-table-column
                    prop="name"
                    label="商品名称">
                  </el-table-column>
                  <el-table-column
                    label="商品图片">
                    <template slot-scope="scope">
                      <el-image :src="scope.row.img">
                      </el-image>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="price"
                    label="商品价格">
                  </el-table-column>
                  <el-table-column
                    prop="createdAt"
                    label="发布日期">
                  </el-table-column>
                  <el-table-column
                    prop="user.username"
                    label="发布人">
                  </el-table-column>
                  <el-table-column
                    label="操作">
                    <template slot-scope="scope">
                      <el-popconfirm
                        title="确定删除该商品吗？"
                        @confirm="confirm(scope.row.id)"
                        confirm-button-type='danger'
                        cancel-button-type='primary'>
                        <el-button type="danger" slot="reference">删除商品</el-button>
                      </el-popconfirm>
                    </template>
                  </el-table-column>
                </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getCateGood} from '@/api/admin/index.js'
import {delGood} from '@/api/admin/index.js'
import {delCollection} from '@/api/admin/index.js'
export default {
  data() {
    return {
      tableData:[]
    }
  },
  methods:{
    init() {
      // console.log(localStorage.getItem('adminor'));
      let cate_id = 1
      getCateGood(cate_id).then(res=>{
        console.log(res.data);
        this.tableData = res.data.data
      })
    },
    confirm(id) {
      console.log(id);
        delGood(id).then(() => {
          this.init()
        })
        delCollection(id).then(() => {
          this.init()
        })
    },
  },
  created() {
    this.init()
  }
}
</script>

<style scoped>

</style>